package com.quanyan.runningriding.web.running.Admin;


import com.quanyan.api.APIResponse;
import com.quanyan.common.validation.base.Update;
import com.quanyan.runningriding.entity.vo.run.req.RunVideoFirstType;
import com.quanyan.runningriding.entity.vo.run.req.RunVideoSecondType;
import com.quanyan.runningriding.entity.vo.run.resp.VideoFirstTypeSimple;
import com.quanyan.runningriding.entity.vo.run.resp.VideoSecondTypeSimple;
import com.quanyan.runningriding.entity.vo.run.resp.VideoTypeCollection;
import com.quanyan.runningriding.service.RunVideoService;
import com.quanyan.runningriding.util.RunEnum;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * RunVideoController
 *
 * @author Tu Chun
 * @date 2016/8/23
 */
@RestController
@RequestMapping(value = "/admin/api/run")
public class VideoTypeAdminController {
    @Autowired
    private RunVideoService runVideoService;
    private Logger logger = LoggerFactory.getLogger(VideoTypeAdminController.class);

    @RequestMapping(value = "/editFirstType", method = RequestMethod.POST)
    public APIResponse<?> editFirstType(@RequestBody @Validated(Update.class) RunVideoFirstType firstType) {
        APIResponse<?> result = runVideoService.editFirstType(firstType);
        return result;
    }

    @RequestMapping(value = "/deleteFirstType", method = RequestMethod.POST)
    public APIResponse<?> deleteFirstType(@RequestBody Map<String, Object> paramMap) {
        Byte firstType = MapUtils.getByte(paramMap, "firstType");
        if (firstType == null) {
            APIResponse.returnFail(RunEnum.PARAMETER_NOT_ALLOW_NULL);
        }
        APIResponse<?> result = runVideoService.deleteFirstType(firstType);
        return result;
    }


    @RequestMapping(value = "/editSecondType", method = RequestMethod.POST)
    public APIResponse<?> editSecondType(@RequestBody @Validated(Update.class) RunVideoSecondType secondType) {
        APIResponse<?> result = runVideoService.editSecondType(secondType);
        return result;
    }

    @RequestMapping(value = "/deleteSecondType", method = RequestMethod.POST)
    public APIResponse<?> deleteSecondType(@RequestBody Map<String, Object> paramMap) {
        Byte firstType = MapUtils.getByte(paramMap, "firstType");
        Byte secondType = MapUtils.getByte(paramMap, "secondType");
        if (firstType == null || secondType == null) {
            APIResponse.returnFail(RunEnum.PARAMETER_NOT_ALLOW_NULL);
        }
        APIResponse<?> result = runVideoService.deleteSecondType(firstType, secondType);
        return result;
    }

    @RequestMapping(value = "/showTypeList", method = RequestMethod.POST)
    public APIResponse<List<VideoTypeCollection>> showTypeList() {
        APIResponse<List<VideoTypeCollection>> result = runVideoService.showTypeList();
        return result;
    }

    @RequestMapping(value = "/getFirstTypeList", method = RequestMethod.POST)
    public APIResponse<List<VideoFirstTypeSimple>> getFirstTypeList() {

        APIResponse<List<VideoFirstTypeSimple>> result = runVideoService.getFirstTypeList();
        return result;
    }

    @RequestMapping(value = "/getSecondTypeList", method = RequestMethod.POST)
    public APIResponse<List<VideoSecondTypeSimple>> getSecondTypeList(@RequestBody Map<String, Object> paramMap) {
        Byte firstType = MapUtils.getByte(paramMap, "firstType");

        if (firstType == null) {
            APIResponse.returnFail(RunEnum.PARAMETER_NOT_ALLOW_NULL);
        }
        APIResponse<List<VideoSecondTypeSimple>> result = runVideoService.getSecondTypeList(firstType);
        return result;
    }


}
